import java.util.HashSet;

class Solution202 {
    public static void main(String[] args) {
        System.out.println(isHappy(2));
    }
    public static boolean isHappy(int n) {
      HashSet<Integer> hash = new HashSet<>() ;
      hash.add(n);
      int tmp = n ;  
      while(tmp != 1){
         tmp = getNum(tmp) ; 
         if(hash.contains(tmp) == true){
            return false ;
         }hash.add(tmp) ;
      }
     return true ;
    }
     private static int getNum(int n){
        long sum = 0 ; 
        while(n > 0){
           sum += (n%10) * (n%10) ; 
           n /= 10 ;
        }
       return (int) sum ; 
     }

}